package org.game.manager;

import java.util.List;

import org.bean.TempRewardDTO;
import org.constant.MailConstant;
import org.game.db.bean.Player;
import org.game.db.cache.PlayerCache;
import org.game.log.builder.LogDsp;
import org.game.log.dsp.GoodsDsp;
import org.utils.RemoteUtil;

import com.xiaoleilu.hutool.util.MapUtil;

/**
 * 线下奖励管理器
 * 
 * @author Alan
 *
 */
public class OfflineRewardManager {
	private OfflineRewardManager() {
	}

	private static OfflineRewardManager ME = new OfflineRewardManager();

	public static OfflineRewardManager me() {
		return ME;
	}

	public void pullRewardInfo(Player player) {
		List<TempRewardDTO> dtos = player.getPlayerProxy().getAccountInfo().getTempRewards();
		if(dtos==null)return;
		dtos.forEach(dto->{receiveRewardInfo(dto);});
		RemoteUtil.loginAsyn().noticeHandleTempReward(player.getPlayerProxy().getAccountInfo().getUid());
	}

	public void receiveRewardInfo(TempRewardDTO rewardDTO) {
		Player player = PlayerCache.me().getByUid(rewardDTO.getUid());
		
		if (player == null)
			return;
		
		LogDsp logDsp = LogDsp.newBuilder(GoodsDsp.OFFLINE_REWARD).addAttr("offlinereward", rewardDTO.getRewardType());
		
		// TODO 国际化数据缓存?
		MailManager.me().sendPersonalMail(0, player.getId(),MailConstant.TEXT_TYPE_CONFIG,"mail.turntable.title","mail.turntable.content", null,rewardDTO.getItems(), logDsp);
	}
}
